package com.example.petstoreservice.entity;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private String statusCode = ResultType.SUCCESS.getCode();
    private String message = ResultType.SUCCESS.getName();
    private T data = null;

    public Result() {
        setStatusCode(statusCode);
        setMessage(message);
    }

    public static <T> Result<T> success(T data) {
        Result<T> res = new Result<>();
        res.setStatusCode(ResultType.SUCCESS.getCode());
        res.setData(data);
        return res;
    }

    public static <T> Result<T> fail() {
        Result<T> res = new Result<>();
        res.setStatusCode(ResultType.FAIL.getCode());
        return res;
    }

    public static <T> Result<T> fail(String message) {
        Result<T> res = new Result<>();
        res.setMessage(message);
        res.setStatusCode(ResultType.FAIL.getCode());
        return res;
    }

    public static <T> Result<T> success(String message) {
        Result<T> res = new Result<>();
        res.setMessage(message);
        res.setStatusCode(ResultType.SUCCESS.getCode());
        return res;
    }
}
